package org.example.factory.messagequeue;

import cn.hutool.core.util.IdUtil;
import org.example.model.messagequeue.Room;
import org.example.model.messagequeue.User;
import org.example.utils.RandomUtils;

import java.time.Instant;
import java.util.ArrayList;
import java.util.List;

/**
 * @author huangy
 * @description 房间工厂
 * @since 2022/11/10 17:05
 **/
public class RoomFactory {

    /*
     * @description 创建房间
     * @author huangy
     * @since 2022/11/10 17:12
     * @return org.example.model.messagequeue.Room
     **/
    public static Room createRoom() {
        Room room = new Room();
        //房间id
        long roomId = IdUtil.getSnowflakeNextId();
        room.setId(roomId);
        room.setName("room" + roomId);
        room.setType(RandomUtils.randomRoomType());
        room.setCode(Instant.now().toEpochMilli());
        List<User> players = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            players.add(UserFactory.createUser());
        }
        room.setPlayers(players);
        return room;
    }

    private RoomFactory() {
        throw new UnsupportedOperationException();
    }

}
